
import 'package:sciolto/POJO/storable.dart';

class Feeling extends Storable{

  int _id;
  int _parentSongId;
  String _content;
  DateTime _time;

  Feeling(this._parentSongId, this._content){
    this._time = DateTime.now();
    this._id = -1;
  }

  Feeling.fromMap(Map<String, dynamic> map){
    assert (map.containsKey('parent_song_id') && map.containsKey('content') && map.containsKey('time') && map.containsKey('id'));
    this._parentSongId = map['parent_song_id'];
    this._content = map['content'];
    this._time = DateTime.parse(map['time']);
    this._id = map['id'];
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is Feeling &&
          runtimeType == other.runtimeType &&
          _id == other._id &&
          _parentSongId == other._parentSongId &&
          _content == other._content &&
          _time == other._time;

  @override
  int get hashCode =>
      _id.hashCode ^
      _parentSongId.hashCode ^
      _content.hashCode ^
      _time.hashCode;

  // ignore: unnecessary_getters_setters
  set content(String value) {
    _content = value;
  }

  // ignore: unnecessary_getters_setters
  String get content => _content;

  int get parentSongName => _parentSongId;

  String get timeInChinese => "${_time.year}年${_time.month}月${_time.day}日 ${_time.hour}时${_time.minute}分";

  int get id => _id;

  String get time => "${_time.year}"
      "-${_time.month < 10 ? '0'+'${_time.month}' : _time.month}"
      "-${_time.day < 10 ? '0'+'${_time.day}' : _time.day}"
      " ${_time.hour < 10 ? '0'+'${_time.hour}' : _time.hour}"
      ":${_time.minute < 10 ? '0'+'${_time.minute}' : _time.minute}"
      ":${_time.second < 10 ? '0'+'${_time.second}' : _time.second}";

  @override
  Map<String, dynamic> toMap(){
    Map<String, dynamic> result = {};
    result['parent_song_id'] = _parentSongId;
    result['content'] = _content;
    result['time'] = time;
    if(_id != -1) result['id'] = _id;
    return result;
  }

}